﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AgileLogistics.View.User.Dep
{
    /// <summary>
    /// Add.xaml 的交互逻辑
    /// </summary>
    public partial class Add : System.Windows.Window
    {
        ViewModel.BaseViewModel vm;
        Model.DBContext dbContext = new Model.DBContext();
        public Add()
        {
            InitializeComponent();
            vm = DataContext as ViewModel.BaseViewModel;

            vm.CurrDep = new  Model.Depment ();

            
        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            if(string.IsNullOrEmpty( vm.CurrDep.Name))
            {
                Growl.WarningGlobal("请输入部门名称");
                return;
            }

            dbContext.DB.Insertable<Model.Depment>(vm.CurrDep).ExecuteCommand();

            Growl.SuccessGlobal("保存成功！");


            vm.DepList = dbContext.DB.Queryable<Model.Depment>().ToList();
            this.Close();
        }
    }
}
